<?php
	include "common.php";
	class Login {
		protected $mUserName;
		protected $mPassword;
		protected $mNickName;
		protected $conn;
		
		function linkMySQL() {
			// 连接MySQL数据库
			$this->conn = mysqli_connect ( HOST, USER, PASS ) or die ( "cant connect database" );
		}
		/* 查询用户信息 */
		function _queryUsers($name, $password) {
			// 连接数据库
			$this->linkMySQL ();
			
			mysqli_select_db($this->conn, CORPORATION);
			$sql = "SELECT * FROM corporation_user where username = '$name' and userpwd = '$password'";
			return mysqli_query ( $this->conn, $sql );
		}
		
		/*释放资源*/
		function releaseRes() {
			// 释放资源
			mysqli_free_result ( $this->result );
			// 关闭连接
			mysqli_close($this->conn);
		}
	}
	
	$name = $_POST ['name'];
	$pass = $_POST ['pawd'];
	
	$loginObj = new Login ();
	$result = $loginObj->_queryUsers ( $name, $pass );
	
	$length = mysqli_fetch_lengths($result);
	
	if ($length > 0) {
		echo "success";
	} else {
		echo "fail";
	}
	
 	// 循环取出记录
// 	while (($row = mysqli_fetch_row($result)) != false){
// 		foreach($row as $data){
// 		    echo $data.' ';
// 		}
// 	}
	
?>